package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbContentMapper;
import com.bw1806.pojo.TbContent;
import com.bw1806.pojo.TbContentExample;
import com.bw1806.sellergoods.service.TbContentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbContentServiceImpl implements TbContentService {

    @Autowired
    private TbContentMapper tbContentMapper;

    @Override
    public List<TbContent> findAll() {
        return tbContentMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbContent> pagelist(TbContent tbContent,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbContentExample example=new TbContentExample();

        TbContentExample.Criteria criteria = example.createCriteria();

        if(tbContent!=null){
            //if(tbContent.getName()!=null && tbContent.getName().length()>0){
            //    criteria.andNameLike("%"+tbContent.getName()+"%");
           // }
        }

        Page<TbContent> page= (Page<TbContent>) tbContentMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbContent tbContent) {
        Long id = tbContent.getId();
        if(id != null && id !=0){
            tbContentMapper.updateByPrimaryKey(tbContent);
        } else{
            tbContentMapper.insert(tbContent);
        }
    }

    @Override
    public TbContent getById(Long id) {
        return tbContentMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbContentMapper.deleteByPrimaryKey(id);
        }
        //tbContentMapper.deletebth(ids);
    }
}
